
public class Test {

	private static Student stud1, stud2, stud3;
	private static Professor prof1, prof2, prof3;
	
	private static ReplaceableTree<Person> rep_tree;
	private static ReplaceableTree<String> rep_tree1;
	
	public static void createStuds(){
		stud1 = new Student("Albert Erster",1);
		stud2 = new Student("Bomba Mitte",2);
		stud3 = new Student("Charlie Letzter",3);
	}
	
	public static void createProfs(){
		prof1 = new Professor("Zasta Last","Please!");
		prof2 = new Professor("Yiva intheMiddle","Beer");
		prof3 = new Professor("Xclient first","More");
	}
	
	public static void testReplacableTree_1(){
		rep_tree1 = new ReplaceableTree<String>("c");
		rep_tree1.add("b");
		rep_tree1.add("k");
		rep_tree1.add("z");
		rep_tree1.add("a");
		rep_tree1.add("x");
		System.out.println(rep_tree1.toString());
	}
	
	public static void testReplacableTree_2(){
		rep_tree = new ReplaceableTree<Person>(stud1);
		rep_tree.add(prof1);
		rep_tree.add(stud2);
		rep_tree.add(prof2);
		rep_tree.add(stud3);
		rep_tree.add(prof3);
		System.out.println(rep_tree.toString());
		
		PostorderTree<Professor> ft = new PostorderTree<Professor>(prof3);
		ft.add(prof2);
		
		System.out.println("Replace some prof 3");
		Iter<Boolean> position2 = rep_tree.search(prof3);
		rep_tree.replace(ft, position2);
		
		System.out.println("New Tree: "+rep_tree);
		
		rep_tree = new ReplaceableTree<Person>(stud1);
		rep_tree.add(prof1);
		rep_tree.add(stud2);
		rep_tree.add(prof2);
		rep_tree.add(stud3);
		rep_tree.add(prof3);
		
		PreorderTree<Student> pt = new PreorderTree<Student>(stud1);
		pt.add(stud2);
		
		System.out.println("Replace Some stud1:");
		Iter<Boolean> position = rep_tree.search(stud1);
		rep_tree.replace(pt, position);
		
		System.out.println("New Tree: "+rep_tree);
	}
	
	public static void testPreorderTree_1(SortedTree<Student> pre_tree){
		pre_tree.add(stud1);
		pre_tree.add(stud3);
		
		System.out.println("Teilbaum ab stud 2: ");
		Iter<Boolean> stud_iter = pre_tree.search(stud2);
		while(stud_iter.hasNext()){
			System.out.println(stud_iter.next());
		}
		
		System.out.println("CONTAINS: ");
		TreeIter<Student> stud2_iter = pre_tree.contains(stud2);
		while(stud2_iter.hasNext()){
			System.out.println(stud2_iter.next());
		}
		
		TreeIter<Student> sorted_iterator = pre_tree.iterator();
		System.out.println("Print next:");
		while(sorted_iterator.hasNext()){
			System.out.println(sorted_iterator.next());
		}
	}
	
	public static void testInorderTree_1(SortedTree<Integer> in_tree){
		in_tree.add(6);
		in_tree.add(7);
		in_tree.add(1);
		in_tree.add(9);
		in_tree.add(8);
		System.out.println("Search 1: ");
		Iter<Boolean> int_iter = in_tree.search(1);
		while(int_iter.hasNext()){
			System.out.println(int_iter.next());
		}
		
		TreeIter<Integer> in_iter = in_tree.contains(1);
		while(in_iter.hasNext()){
			System.out.println(in_iter.next());
		}
	}
	
	public static void testPostorderTree_1(SortedTree<Professor> post_tree){
		post_tree.add(prof1);
		post_tree.add(prof2);
		
		System.out.println("Teilbaum ab prof 2: ");
		Iter<Boolean> stud_iter = post_tree.search(prof2);
		while(stud_iter.hasNext()){
			System.out.println(stud_iter.next());
		}
		
		System.out.println("CONTAINS: ");
		TreeIter<Professor> stud2_iter = post_tree.contains(prof2);
		while(stud2_iter.hasNext()){
			System.out.println(stud2_iter.next());
		}
		
		TreeIter<Professor> sorted_iterator = post_tree.iterator();
		System.out.println("Print next:");
		while(sorted_iterator.hasNext()){
			System.out.println(sorted_iterator.next());
		}
	}
	
	public static void testSortedTree_2(SortedTree<Person> sorted_tree){
		System.out.println("Test "+sorted_tree.getClass().getName()+"<"+sorted_tree.getClass().getComponentType().getName()+">");
		
		TreeIter<Person> sorted_iterator = sorted_tree.iterator();
		System.out.println("Print next:");
		while(sorted_iterator.hasNext()){
			System.out.println(sorted_iterator.next().getName());
		}
		System.out.println("Print previous:");
		while(sorted_iterator.hasPrevious()){
			System.out.println(sorted_iterator.previous().getName());
		}
	}

	public static void main(String[] args) {
		createStuds();
		createProfs();
		
		Testcase1();
		Testcase2();
		Testcase3();
	}
	
	public static void Testcase1(){
		System.out.println("---------------------------------------------------------");
		System.out.println("----------------Generic Tree's Test #1-------------------");
		System.out.println();
		
		System.out.println("-------------Test ReplacableTree <String>----------------");
		testReplacableTree_1();
		System.out.println("---------------End of ReplacableTree---------------------");
		
		System.out.println("-------------Test Preorder Tree<Student>-----------------");
		try{
			testPreorderTree_1(new PreorderTree<Student>(stud2));
		} catch(Exception e){
			System.out.println("exception in testPreorderTree! "+e.getMessage());
		}
		System.out.println("----------------End of Preorder Tree---------------------");
		System.out.println();
		
		System.out.println("------------Test Inorder Tree<Integer>-------------------");
		try{
			testInorderTree_1(new InorderTree<Integer>(3));
		} catch(Exception e){
			System.out.println("exception in testInorderTree! "+e.getMessage());
		}
		System.out.println("-----------------End of Inorder Tree---------------------");
		System.out.println();
		
		System.out.println("-----------Test Postorder Tree<Postorder>----------------");
		try{
			testPostorderTree_1(new PostorderTree<Professor>(prof3));
		} catch(Exception e){
			System.out.println("exception in testPostorderTree! "+e.getMessage());
		}
		System.out.println("----------------End of Postorder Tree--------------------");
		System.out.println();
	}
	
	public static void Testcase2(){
		System.out.println("---------------------------------------------------------");
		System.out.println("----------------Generic Tree's Test #2-------------------");
		System.out.println();
		
		System.out.println("----------------Test ReplacableTree----------------------");
		testReplacableTree_2();
		System.out.println("---------------End of ReplacableTree---------------------");
		System.out.println("------------------END OF TEST----------------------------");
	}
	
	public static void Testcase3(){
		ReplaceableTree<Person> rep = new ReplaceableTree<Person>(stud1);
		rep.add(stud2);
		rep.add(stud3);
		rep.add(prof1);
		rep.add(prof2);
		rep.add(prof3);
		
		System.out.println(rep);
		
		TreeIter<Person> downiter = rep.iterator();
		while(downiter.hasNext()){
			System.out.println(downiter.next());
			System.out.println(" schow tree with down ");
			TreeIter<Person> di2 = downiter.down();
			while(di2.hasNext()){
				System.out.println(" - " + di2.next());
			}
		}
		//downiter.
		/*
		ReplaceableTree<Professor> repp = new ReplaceableTree<Professor>(new Professor("Michael B","z"));
		repp.add(new Professor("Nike Blamed","a"));
		repp.add(new Professor("Qulibald Arm","h"));
		
		ReplaceableTree<Student> reps = new ReplaceableTree<Student>(new Student("Oman B",100));
		reps.add(new Student("Patrick Kahn",1001));
		reps.add(new Student("Herbst Maier",1002));
		
		System.out.println("After Down:");
		Iter<Boolean> pway = rep.search(prof1);
		Iter<Boolean> sway = rep.search(stud3);
		
		rep.replace(repp, pway);
		rep.replace(reps, sway);*/
		
	}
}
